//
//  BaseTableViewController.swift
//  WeiBo test
//
//  Created by Aquarius_wing on 16/5/4.
//  Copyright © 2016年 Wing. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate {

    //userLogin去判断是否有这个文件存在,存在为真
    var userLogin = UserAccountViewModel().userLogin
//    var userLogin = UserAccount.loadAccount() != nil
//    var userLogin = false
    var visitorLoginView:VisitorLoginView?
    //loadView是苹果专门为手写代码准备的 等效于 sb / xib 
    //一旦实现这个方法   sb / xib 自动失效
    //会自动检测 view 是否为空 如果为空 会自动调用 loadView 方法
    override func loadView() {
        //如果已经登录过
        userLogin ? super.loadView() : loadVisitorView()
        
    }
    
    
    
    private func loadVisitorView(){
        visitorLoginView=VisitorLoginView()
        visitorLoginView?.visitorDelegate=self
        view=visitorLoginView
        self.navigationItem.leftBarButtonItem=UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(BaseTableViewController.visitorWillRegister))
        self.navigationItem.rightBarButtonItem=UIBarButtonItem(title: "登录", style: .Plain, target: self, action: #selector(BaseTableViewController.visitorWillLogin))
        
        //要设置两个按钮的主题色,跑到文件AppDelegate中setThemeColor()
    }
    
    //MARK: 协议方法
    
    func visitorWillRegister() {
        print("register")
    }
    
    func visitorWillLogin() {
        print("login")
        let oauth=OAuthViewController()
        let nav=UINavigationController(rootViewController: oauth)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    //视图控制器
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

}
